<?php
// 本类由系统自动生成，仅供测试用途
class CommonAction extends Action {
    protected $sys;
	protected $auth;
	protected $art;

	public function __construct(){
	    
	    //看一下是否是推广连接
	    $this->assign('tuiguang',$_GET['invit']);
        //清空超过12个小时
		$Sys = D('Sys');
        $this->sys = $Sys->where('id=1')->find();
        $this->sys['invitfen']=floatval($this->sys['invitfen']);
		$this->assign('sys',$this->sys);

		//币种
		$this->assign('bname',$this->sys['kgname']);
		


		$Art = D('Art');
        $this->art = $Art->order('id asc')->select();
		$this->assign('art',$this->art);

		$about = $Art->where('cate="about"')->order('id asc')->limit(6)->select();
		$this->assign('about',$about);

		$help = $Art->where('cate="help"')->order('id asc')->limit(6)->select();
		$this->assign('help',$help);

		$news = $Art->where('cate="news"')->order('id asc')->limit(6)->select();
		$this->assign('news',$news);

		$serv = $Art->where('cate="serv"')->order('id asc')->limit(6)->select();
		$this->assign('serv',$serv);

		$this->assign('path',C('URL_DIR'));
		$this->assign('pubdir',C('PUB_DIR'));
		
		$map['ctime']=array('between',array(strtotime(date('y-m-d'),time()),time()));
		$map['type']=1;
		$count=M('Trans')->where($map)->sum('num');//数量
		$money=M('Trans')->where($map)->sum('num*price');//数量
		$this->assign('count',$count);
		$this->assign('money',$money);

        $User = D('User');
		$this->auth = $User->where('id='.$_SESSION['USER_KEY_ID'])->lock(true)->find();
        $this->auth['rmb'] = floatval($this->auth['rmb']);
		$this->auth['rmb_frozen'] = floatval($this->auth['rmb_frozen']);
		$this->auth['xnb'] = floatval($this->auth['xnb']);
		$this->auth['xnb_frozen'] = floatval($this->auth['xnb_frozen']);
		$this->auth['ks'] = floatval($this->auth['ks']);
		$this->auth['ks_frozen'] = floatval($this->auth['ks_frozen']);
		$this->auth['rmbtotal'] = floatval($this->auth['rmb']+$this->auth['rmb_frozen']);
		$this->auth['kgtotal'] = floatval($this->auth['xnb']+$this->auth['xnb_frozen']);
		$this->auth['kstotal'] = floatval($this->auth['ks']+$this->auth['ks_frozen']);
		$this->auth['total'] = floatval($this->auth['rmb']+$this->auth['rmb_frozen']);
		
		$this->assign('auth',$this->auth);

		$this->assign('act',$_GET['_URL_'][1]);
		$this->assign('fun',$_GET['_URL_'][2]);

		$Orders = D('Orders');
		$kglast = $Orders->where('coin="kg"')->order('ctime desc')->find();
		$kslast = $Orders->where('coin="ks"')->order('ctime desc')->find();
		$this->assign('kglast',floatval($kglast['price']));
		$this->assign('kslast',floatval($kslast['price']));

		$this->assign('invit',$_SESSION['invit']);
		$user=M("User")->where("id='{$_SESSION['USER_KEY_ID']}'")->find();
		$this->assign("user",$user);
		
		//认购价格
		$issue=M("Issue")->where("status = 0")->order("ctime desc")->find();
		$buynum=M("Buy")->where("iid='{$issue['id']}'")->sum("num");
		$issue['yirengou']=$buynum;
		
		$this->assign("issuer_index",$issue);
	}

	protected function checkAuth(){
		if (!$_SESSION['USER_KEY'] || !$_SESSION['USER_KEY_ID']) {
			$_SESSION['notlogin']=1;
			redirect('/Home/Index/index', 0, '页面跳转中...');
			exit(0);
		}
	}

    protected function checkReal(){
		$_SESSION['prev_url'] = $_SERVER['HTTP_REFERER'];
		if(!chkStr($this->auth['xm'])||!chkStr($this->auth['idnumber'])||!chkStr($this->auth['phone']))
			echo '<script language="javascript">alert("您的资料没有填写完整，请完成资料填写后在进行此操作！");location.href="/?s=Home/User/real";</script>';
	}

	protected function checkAuthAjax(){
		if (!$_SESSION['USER_KEY'] || !$_SESSION['USER_KEY_ID']) {
			return false;
			exit(0);
		}else{
		    return true;
		}
	}

	protected function sendEmail($uemail,$title,$content){

	    require("class.phpmailer.php");

        if($this->sys['smtp']=='smtp.gmail.com'){
			$mail = new PHPMailer();
			$mail->IsSMTP();
			$mail->CharSet='UTF-8';
			$mail->Host = C('SMTP');
			$mail->SMTPAuth = true;
			$mail->SMTPSecure = "ssl"; 
			$mail->Port = "465";
			$mail->Username = $this->sys['email'];
			$mail->Password = $this->sys['pwd'];
			$mail->From = $this->sys['email'];
			$mail->FromName = $this->sys['auth'];
			$mail->AddAddress($uemail, "user");
			$mail->IsHTML(true);
			$mail->Subject = $title;
			$mail->Body = $content;
			$mail->SMTPDebug=false;

			if(!$mail->Send())
			{
				return false;
			}else{
				return true;
			}
		}else{
			$mail = new PHPMailer();
			$mail->IsSMTP();
			$mail->CharSet='UTF-8';
			$mail->Host = C('SMTP');
			$mail->SMTPAuth = true;
			$mail->Port = "25";
			$mail->Username = $this->sys['email'];
			$mail->Password = $this->sys['pwd'];
			$mail->From = $this->sys['email'];
			$mail->FromName = $this->sys['auth'];
			$mail->AddAddress($uemail, "user");
			$mail->IsHTML(true);
			$mail->Subject = $title;
			$mail->Body = $content;
			$mail->SMTPDebug=false;

			if(!$mail->Send())
			{
				return false;
			}else{
				return true;
			}
		}
	}
	protected function tel_fasong($tel,$neirong,$num){
		$statusStr = array(
				"0" => "短信发送成功",
				"-1" => "参数不全",
				"-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
				"30" => "密码错误",
				"40" => "账号不存在",
				"41" => "余额不足",
				"42" => "帐户已过期",
				"43" => "IP地址限制",
				"50" => "内容含有敏感词"
		);
		$smsapi = "http://api.smsbao.com/"; //短信网关
		$user = laitou; //短信平台帐号
		$pass = md5(laitouadmin); //短信平台密码
// 		$content="短信内容";//要发送的短信内容
		$content=$neirong;
// 		$phone = "*****";//要发送短信的手机号码
		$phone=$tel;
		$sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
		$result =file_get_contents($sendurl) ;
		$_SESSION['code']=$num;
		echo $statusStr[$result];
	}

}